﻿Shader "Custom RP/Lit" {
	
	Properties {
		[KeywordEnum(Standard, Skin, Fabric, SSSSS, Scene)] _MaterialType ("Material Type", Float) = 0

		_BaseMap("Texture", 2D) = "white" {}
		_BaseColor("Color", Color) = (0.5, 0.5, 0.5, 1.0)
		_Cutoff ("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
		[Toggle(_CLIPPING)] _Clipping ("Alpha Clipping", Float) = 0
		[Toggle(_RECEIVE_SHADOWS)] _ReceiveShadows ("Receive Shadows", Float) = 1
		[KeywordEnum(On, Clip, Dither, Off)] _Shadows ("Shadows", Float) = 0

		[Toggle(_MASK_MAP)] _MaskMapToggle ("Mask Map", Float) = 0
		[NoScaleOffset] _MaskMap("Mask (MODS)", 2D) = "white" {}
		_Metallic ("Metallic", Range(0, 1)) = 0
		_Occlusion ("Occlusion", Range(0, 1)) = 1
		_Smoothness ("Smoothness", Range(0, 1)) = 0.5
		_Fresnel ("Fresnel", Range(0, 1)) = 1

		[Toggle(_NORMAL_MAP)] _NormalMapToggle ("Normal Map", Float) = 0
		[NoScaleOffset] _NormalMap("Normals", 2D) = "bump" {}
		_NormalScale("Normal Scale", Range(0, 1)) = 1

		[NoScaleOffset] _EmissionMap("Emission", 2D) = "white" {}
		[HDR] _EmissionColor("Emission", Color) = (0.0, 0.0, 0.0, 0.0)

		[Toggle(_DETAIL_MAP)] _DetailMapToggle ("Detail Maps", Float) = 0
		_DetailMap("Details", 2D) = "linearGrey" {}
		[NoScaleOffset] _DetailNormalMap("Detail Normals", 2D) = "bump" {}
		_DetailAlbedo("Detail Albedo", Range(0, 1)) = 1
		_DetailSmoothness("Detail Smoothness", Range(0, 1)) = 1
		_DetailNormalScale("Detail Normal Scale", Range(0, 1)) = 1
		
		[Toggle(_PREMULTIPLY_ALPHA)] _PremulAlpha ("Premultiply Alpha", Float) = 0

		[Enum(UnityEngine.Rendering.BlendMode)] _SrcBlend ("Src Blend", Float) = 1
		[Enum(UnityEngine.Rendering.BlendMode)] _DstBlend ("Dst Blend", Float) = 0
		[Enum(Off, 0, On, 1)] _ZWrite ("Z Write", Float) = 1
		[HideInInspector][Enum(UnityEngine.Rendering.CullMode)] _CullMode("_CullMode", float) = 2.0

		[HideInInspector] _MainTex("Texture for Lightmap", 2D) = "white" {}
		[HideInInspector] _Color("Color for Lightmap", Color) = (0.5, 0.5, 0.5, 1.0)

		//----------------Scene wind grass animation-----------------
		[Main(_WindGrassGroup, _WINDGRASS, 1)] _WindGrassGroup("WindGrassAnimation", float) = 0
		[Sub(_WindGrassGroup)] _Wind("Wind params（XZ for Direction,W for Weight Scale)",Vector) = (1,0.2,1,0.1)
		[Sub(_WindGrassGroup)] _WindEdgeFlutterFreqScale("Wind Freq Scale",float) = 0.1
		[Sub(_WindGrassGroup)] _ColliderRadius("Collider Radius",Range(0,4)) = 1.0
		[Sub(_WindGrassGroup)] _PlayerForce("Player Force",float) = 1.0
		[Sub(_WindGrassGroup)] _ForceY("Collider Force Y ",Range(-1,1)) = -1.0
		//----------------Scene wind grass animation-----------------

		//----------------Scene Vegetation Tree animation-----------------
		[Main(_VegetationTreeGroup, _VEGETATION_TREE, 1)] _VegetationTreeGroup("VegetationTree", float) = 0
		[SubToggle(_VegetationTreeGroup, USE_VERTEXANIM)] _UseVertexAnim("UseVertexAnim", Float) = 0		
		[Sub(_VegetationTreeGroup)] _VertAnim_Offset("VertAnim_Offset", Range(0,2)) = 0.01
		[Sub(_VegetationTreeGroup)] _VertAnim_Speed("VertAnim_Speed", Range(0,10)) = 0
		[Sub(_VegetationTreeGroup)] _VertAnim_Frequency("VertAnim_Frequency", Range(0,60)) = 0
		[Sub(_VegetationTreeGroup)] _OccAmount("OCC (vertexColor.r)", Range(0,1)) = 0
		[Sub(_VegetationTreeGroup)] _EmissionVal("Emi Mask(vertexColor.g)",float) = 0.0
		//----------------Scene Vegetation Tree animation-----------------

		//----------------Scene Vegetation Tree animation-----------------
		[Main(_UVANIMATIONGroup, _UVANIMATION, 1)] _UVANIMATIONGroup("UVANIMATION", float) = 0
		[Sub(_UVANIMATIONGroup)] _USpeed("U-speed", Float) = 0
		[Sub(_UVANIMATIONGroup)] _VSpeed("V-speed", Float) = 0
		//----------------Scene Vegetation Tree animation-----------------

		//----------------IBL-----------------
		[Main(_IBLGroup, _IBL, 1)] _IBLGroup ("ReceiveIBL", float) = 0
		[Sub(_IBLGroup)] _IrradianceScale("Irradiance Scale", Range(0, 2)) = 1.0
		[Sub(_IBLGroup)] _SpecularReflectScale("SpecularReflect Scale", Range(0, 2)) = 1.0
		//----------------IBL-----------------

		//----------------Skin-------------------
		// BRDF Lookup texture, light direction on x and curvature on y.
		[Main(_PreIntegratedSSSGroup, __, 3)] _PreIntegratedSSSGroup ("PreIntegratedSSS", float) = 0
		[Tex(_PreIntegratedSSSGroup, _)]_BRDFTex("BRDF Lookup (RGB)", 2D) = "gray" {}
		[Tex(_PreIntegratedSSSGroup, _)]_SSSTex("Curvature(R) thickness(G)", 2D) = "gray" {}
		[Sub(_PreIntegratedSSSGroup)]_CurvatureScale("Curvature Scale (0.0 - 1.0)", Float) = 1
		[Sub(_PreIntegratedSSSGroup)]_ThicknessScale("Subsurface Scale (0.0 - 1.0)", Float) = 0.5
		[HDR] [Sub(_PreIntegratedSSSGroup)]_SubColor("Subsurface Color", Color) = (1, .4, .25, 1)
		[Sub(_PreIntegratedSSSGroup)]_Power("Subsurface Power", Float) = 1
		[Sub(_PreIntegratedSSSGroup)]_Distortion("Subsurface Distortion (0.0 - 0.1)", Range(0, 1)) = 0 
		//----------------Skin-------------------	
		
		//----------------Fabric-----------------
		[Main(_FabricScatterGroup, __, 3)] _FabricScatterGroup ("FabricScatter", float) = 0
		[Sub(_FabricScatterGroup)]_FabricScatterColor("Fabric Scatter Color", Color) = (1,1,1,1)
		[Sub(_FabricScatterGroup)]_FabricScatterScale("Fabric Scatter Scale", Range(0, 2)) = 1
		//----------------Fabric-----------------

		//----------------SSSSS-----------------
		[Main(_SSSSSGroup, __, 3)] _SSSSSGroup ("SSSSScatter", float) = 0
		[Sub(_SSSSSGroup)]_SSSSScatterColor("SSSS Scatter Color", Color) = (1,1,1,1)
		[Sub(_SSSSSGroup)]_SSSSSMap("Texture", 2D) = "white" {}
		//----------------SSSSS-----------------

	}
	
	SubShader {
		HLSLINCLUDE
		#include "../ShaderLibrary/Common.hlsl"
		#include "LitInput.hlsl"

		#pragma shader_feature _STANDARD _SKIN _FABRIC _SSSSS
		#pragma shader_feature _WINDGRASS  
		#pragma shader_feature _UVANIMATION
		#pragma shader_feature _VEGETATION_TREE
		#pragma shader_feature USE_VERTEXANIM
		#pragma shader_feature _IBL
		#pragma shader_feature _IBL_RP_ON

		#pragma enable_d3d11_debug_symbols

		//#define _DEBUG_HLSL_ 1
		//#pragma shader_feature _DEBUG_HLSL_
		//#include "../ShaderLibrary/_Debug_.hlsl"
		
		ENDHLSL
		Pass {
			Tags {
				"LightMode" = "CustomLit"
			}

			Blend [_SrcBlend] [_DstBlend], One OneMinusSrcAlpha
			ZWrite [_ZWrite]
			Cull [_CullMode]

			HLSLPROGRAM
			#pragma target 3.5
			#pragma shader_feature _CLIPPING
			#pragma shader_feature _RECEIVE_SHADOWS
			#pragma shader_feature _PREMULTIPLY_ALPHA
			#pragma shader_feature _MASK_MAP
			#pragma shader_feature _NORMAL_MAP
			#pragma shader_feature _DETAIL_MAP
			#pragma multi_compile _ _DIRECTIONAL_PCF3 _DIRECTIONAL_PCF5 _DIRECTIONAL_PCF7
			#pragma multi_compile _ _OTHER_PCF3 _OTHER_PCF5 _OTHER_PCF7
			#pragma multi_compile _ _CASCADE_BLEND_SOFT _CASCADE_BLEND_DITHER
			#pragma multi_compile _ _SHADOW_MASK_ALWAYS _SHADOW_MASK_DISTANCE
			#pragma multi_compile _ _LIGHTS_PER_OBJECT
			#pragma multi_compile _ LIGHTMAP_ON
			#pragma multi_compile _ LOD_FADE_CROSSFADE
			#pragma multi_compile_instancing
			#pragma vertex LitPassVertex
			#pragma fragment LitPassFragment
			#include "LitPass.hlsl"
			ENDHLSL
		}

		Pass {
			Tags {
				"LightMode" = "ShadowCaster"
			}

			ColorMask 0
			
			HLSLPROGRAM
			#pragma target 3.5
			#pragma shader_feature _ _SHADOWS_CLIP _SHADOWS_DITHER
			#pragma multi_compile _ LOD_FADE_CROSSFADE
			#pragma multi_compile_instancing
			#pragma vertex ShadowCasterPassVertex
			#pragma fragment ShadowCasterPassFragment
			#include "ShadowCasterPass.hlsl"
			ENDHLSL
		}

		Pass {
			Tags {
				"LightMode" = "Meta"
			}

			Cull Off

			HLSLPROGRAM
			#pragma target 3.5
			#pragma vertex MetaPassVertex
			#pragma fragment MetaPassFragment
			#include "MetaPass.hlsl"
			ENDHLSL
		}

		Pass {
			Tags {
				"LightMode" = "SSSSSSMask"
			}
			Cull Off

			HLSLPROGRAM
			#pragma target 3.5
			#pragma vertex SSSSSMaskPassVertex
			#pragma fragment SSSSSMaskPassFragment
			//#include "../ShaderLibrary/Common.hlsl"
			#include "LitInput.hlsl"
			#include "SSSSSMaskPass.hlsl"
			ENDHLSL
		}
	}

	CustomEditor "CustomShaderGUI"
}